﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace PIS.TechGrid.Studies.Caching
{
    public class MemoryCacheTest
    {
        [TestMethod]
        public void MemoryCache_RefTest()
        {
            CacheItemPolicy policy = new CacheItemPolicy();
            policy.AbsoluteExpiration = DateTime.Now.AddHours(1);

            TestCls a = new TestCls() { A = "A1" };
            MemoryCache mc = MemoryCache.Default;

            mc.Add("A", a, policy);

            var a1 = mc.Get("A") as TestCls;
            var a2 = mc.Get("A") as TestCls;
            a2.A = "A2";

            Assert.IsTrue(Object.ReferenceEquals(a1, a2));
        }

        #region Testing Support

        public class TestCls
        {
            public string A { get; set; }
        }

        #endregion
    }
}
